import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.sax.handler.MapRowHandler;
import com.example.bean.Viru;
import com.example.mapper.ViruMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import cn.hutool.Hutool;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class ImportUtil {

    @Autowired
    ViruMapper viruMapper;

    @Test
    public void test() {
        File file = FileUtil.file("/home/yk/桌面/病毒数据/Small molecular.xlsx");
        //构建阅读的map

        /**
         * {
         *     "Standard Relation": "'='",
         *     "Standard Units": "nM",
         *     "Assay Type": "F",
         *     "Standard Type": "EC50",
         *     "Molecule Max Phase": 0,
         *     "Assay Cell Type": "None",
         *     "Smiles": "C=C(CC(=O)Nc1ccc(F)cc1F)C(=O)Nc1ccc(F)cc1F",
         *     "Target Name": "Influenza A virus",
         *     "Standard Value": 3750
         * }
         */
        ExcelUtil.readBySax(file, 0, new MapRowHandler(0, 1, Integer.MAX_VALUE) {
            @Override
            public void handleData(int sheetIndex, long rowIndex, Map<String, Object> data) {
                Dict dict = new Dict(data);
                log.debug("{}", JSONUtil.toJsonPrettyStr(data));
                Viru viru = new Viru();
                viru.standard_Relation = dict.getStr("Standard Relation");
                viru.standard_Units = dict.getStr("Standard Units");
                viru.assay_Type = dict.getStr("Assay Type");
                viru.standard_Type = dict.getStr("Standard Type");
                viru.molecule_Max_Phase = dict.getInt("Molecule Max Phase");
                viru.assay_Cell_Type = dict.getStr("Assay Cell Type");
                viru.smiles = dict.getStr("Smiles");
                viru.target_Name = dict.getStr("Target Name");
                viru.standard_Value = dict.getInt("Standard Value");

            }
        });

    }
}
